<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <!--手机html -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <title>{{website_title}}</title>
    <link rel="shortcut icon" href="/static/img/favicon.ico"/>
    <link rel="bookmark" href="/static/img/favicon.ico"/>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/css/vmaig.css">
    <link rel="stylesheet" href="/static/css/vmaig_comments.css">
    <link rel="stylesheet" href="/static/css/vmaig_auth.css">
    <link rel="stylesheet" href="/static/jquery/jquery.Jcrop.min.css">

    <script src="/static/jquery/jquery-2.1.3.min.js"></script>
    <script src="/static/jquery/jquery.cookie.js"></script>
    <script src="/static/jquery/jquery.form.js"></script>
    <script src="/static/jquery/jquery.Jcrop.min.js"></script>
    <script src="/static/bootstrap/js/bootstrap.min.js"></script>

    
</head>
<body id="vmaig">
    <!-- 导航栏 -->
    {% url 'index-view' as index_url %}
{% url 'all-view' as all_url %}
{% url 'news-view' as news_url %}


<header id="vmaig-header" class="navbar navbar-inverse navbar-fixed-top navbar-vmaig">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#vmaig-navbar-collapse">
                <span class="sr-only">切换导航</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <div class="navbar-brand">{{website_title}}</div>
        </div>
        <div class="collapse navbar-collapse" id="vmaig-navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="">
                <a href="{{index_url}}">
                    <span class="glyphicon glyphicon-home"></span>
                    首页
                </a>
                </li>
                
                
                
            </ul>
            <ul class="nav navbar-nav navbar-right">
                
                <li class="dropdown">
                <a href="javascript:;" style="padding:5px;" data-toggle="dropdown">
                        <img src="/static/img/default.jpg" alt="" width="40">
                        &nbsp;{{request.session.username}}
                        <span class="badge" style="background-color: #D94600;">{{notification_count}}</span>
                        
                        
                </a>
                <ul class="dropdown-menu navbar-right">
                    
                    <li><a href="/blog/column.html">
                        <span class="glyphicon glyphicon-log-out"></span>
                        切换论坛</a></li>

                     <li><a href="/">
                        <span class="glyphicon glyphicon-log-out"></span>
                        返回主页</a></li>
                     <li><a  href="/login.html">
                        <span class="glyphicon glyphicon-log-out"></span>
                        退出登录</a></li>
                </ul>
                </li>
                
            </ul>

            <!--
            <span class="navbar-text navbar-right">----分享Geek生活</span>
            -->
        </div>
    </div>
</header>



    
    <!-- 文章列表 与 侧边的东西 -->
    <div id="vmaig-main">
        <div id="vmaig-content" class="container">
            
        




{% for item in column %}
<div class="col-md-4">
<div class="panel panel-warning" >
     <div class="panel-heading">
        <div class="row">
            <div class="col-md-6">
                <h3 class="panel-title">{{item.name}}</h3>
            </div>
            {% ifequal item.username.username request.session.username %}
            <div class="col-md-3">
                <h3 class="panel-title pull-right" data-toggle="modal" data-target="#myModal" onclick='modify("{{item.id}}")'>修改</h3>
            </div>
            <div class="col-md-3 ">
                <h3 class="panel-title pull-left" data-toggle="modal" data-target="#myModal" onclick='delete2("{{item.id}}")'>删除
               
                </h3>
            </div>
            {% endifequal %}
        </div>
    </div>
    <div class="panel-body" style="height:150px" onclick=window.location.href="/blog/index.html?column={{item.id}}">
        
            <h5>{{item.summary}}</h5>
        

    </div>
    <div class="panel-footer">
        日期:{{item.create_time|date:"Y-m-d" }}&nbsp;&nbsp;|&nbsp;&nbsp;创建者:{{item.username.name}}&nbsp;&nbsp;|&nbsp;&nbsp;
        {% if item.class_id  %} {{item.class_id}}
        {% else %}公开{% endif %}
    </div>

</div>
</div>
{% endfor %}

{% ifnotequal request.session.role '2'%}

    <div style="height:50px"></div>
<button type="button" class="btn btn- btn-info btn-lg btn-block" data-toggle="modal" data-target="#myModal" onclick='create()'>创建一个新论坛</button>





<form role="form" method="post" action="">
    {% csrf_token %}
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">创建论坛</h4>
            </div>
            <div class="modal-body">
                <input type="text" name="id" class="form-control" style="display:none">
                 <div class="form-group">
                    
                    <label>论坛名称</label>
                    <input type="text" name="name" class="form-control">
                    <label>论坛简介</label>
                    <textarea rows="8" name="summary" class="form-control"></textarea>
                </div>
                <label>论坛权限</label>
                <div class="form-group">
                    
                    
                    <label class="checkbox-inline">
                        <input type="checkbox" name="class"  value="" >公开
                    <label class="checkbox-inline">
                </div>        
                    {% for item in myclass %}
                    <div class="form-group">
                    <label class="checkbox-inline">
                        <input type="checkbox" name="class"  value="{{item.class_id}}" >{{item.class_id}}|{{item.class_name}}|{{item.class_address}}|{{item.class_time}}
                    <label class="checkbox-inline">
                        </div>
                    {% endfor %}


            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

                <button type="submit" class="btn btn-primary" name="" id="btn">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</form>



<script type="text/javascript">
function modify(id)
{
     var xmlhttp;
   
  
    // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
    xmlhttp=new XMLHttpRequest();

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            var data=JSON.parse(xmlhttp.responseText);
            var name=data["name"]
            var summary=data["summary"]
            var class_id=data["class_id"]
            $('input[name=class]').attr("checked",false);
            $("input[name=id]").val(id)
            $("input[name=name]").val(name)
           
            $("textarea[name=summary]").val(summary)
            
            class_id=class_id.split(",")

            

            class_id.forEach(function(e){
                
                $('input[name=class][value="'+e+'"').attr("checked",'checked'); 
            })
            $("#btn").attr("name","modify")
            $("#btn").html("确认修改")
        }
    }
    xmlhttp.open("GET","/api/BlogColumn.html?id="+id,true);
    xmlhttp.send()
   


}

function delete2(id,name,summary,class_id)
{
     var xmlhttp;
   
  
    // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
    xmlhttp=new XMLHttpRequest();

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            var data=JSON.parse(xmlhttp.responseText);
            var name=data["name"]
            var summary=data["summary"]
            var class_id=data["class_id"]
            $('input[name=class]').attr("checked",false);
            $("input[name=id]").val(id)
            $("input[name=name]").val(name)
           
            $("textarea[name=summary]").val(summary)
            
            class_id=class_id.split(",")
            class_id.forEach(function(e){
                
                $('input[name=class][value="'+e+'"').attr("checked",'checked'); 
            })
            $("#btn").attr("name","delete")
            $("#btn").html("确认删除")
        }
    }
    xmlhttp.open("GET","/api/BlogColumn.html?id="+id,true);
    xmlhttp.send()

    


}

function create()
{
    $("input[name=id]").val("")
    $("input[name=name]").val("")
   
    $("textarea[name=summary]").val("")
    

}

</script>

{% endifnotequal %}
<script type="text/javascript" src="/static/js/vmaig.js"></script>
</div>
        <footer>
           <div class="container">
               <p class="text-center">基于Dajngo1.8,Bootsratp3, <a href="/sitemap.xml">网站地图</a></p>
           </div>
        </footer>
    </div>

</body>
